<?php

namespace app\common\service;

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;

class OauthService
{
    //三网通手机号码一键登录
    //阿里云号认证接口
    public static function aliLoginGetMobile($token = '')
    {
        // Download：https://github.com/aliyun/openapi-sdk-php
        // Usage：https://github.com/aliyun/openapi-sdk-php/blob/master/README.md
        $accessKeyId     = '';
        $accessKeySecret = '';
        AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret)
            ->regionId('cn-hangzhou')
            ->asDefaultClient();

        try {
            $result = AlibabaCloud::rpc()
                ->product('Dypnsapi')
                ->scheme('https')// https | http
                ->version('2017-05-25')
                ->action('GetMobile')
                ->method('POST')
                ->host('dypnsapi.aliyuncs.com')
                ->options([
                    'query' => [
                        'RegionId'    => "cn-hangzhou",
                        'AccessToken' => $token
                    ],
                ])
                ->request();

            return array('status' => 'success', 'data' => $result->toArray());
        } catch (ClientException $e) {
            return array('status' => 'failed', 'code' => $e->getErrorCode(), 'msg' => $e->getErrorMessage());
        } catch (ServerException $e) {
            return array('status' => 'failed', 'code' => $e->getErrorCode(), 'msg' => $e->getErrorMessage());
        }
    }

}
